home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / CellEditor.java < prev    next >
Text File  |  1998-06-30  |  6KB  |  143 lines

  1. /*
  2.  * @(#)CellEditor.java    1.9 98/02/05
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing;
  22.  
  23. /**
  24.  * This interface defines the methods any general editor should be able
  25.  * to implement. <p>
  26.  *
  27.  * Having this interface enables complex components (the client of the
  28.  * editor) such as JList, JTree, and JTable to allow any generic editor to
  29.  * edit values in a table cell, or tree cell, etc.  Without this generic
  30.  * editor interface, JTable would have to know about specific editors,
  31.  * such as JTextField, JCheckBox, JComboBox, etc.  In addition, without
  32.  * this interface, clients of editors such as JTable would not be able
  33.  * to work with any editors developed in the future by the user
  34.  * or a 3rd party ISV. <p>
  35.  *
  36.  * To use this interface, a developer creating a new editor can have the
  37.  * new component implement the interface.  Or the developer can
  38.  * choose a wrapper based approch and provide a companion object which
  39.  * implements the CellEditor interface (See JCellEditor for example).  The
  40.  * wrapper approch is particularly useful if the user want to use a
  41.  * 3rd party ISV editor with JTable, but the ISV didn't implement the
  42.  * CellEditor interface.  The user can simply create an object that
  43.  * contains an instance of the 3rd party editor object and "translate"
  44.  * the CellEditor API into the 3rd party editor's API.
  45.  *
  46.  * @version 1.9 02/05/98
  47.  * @author Alan Chung
  48.  * @see event.CellEditorListener
  49.  */
  50.  
  51. import java.util.EventObject;
  52. import com.sun.java.swing.*;
  53. import com.sun.java.swing.event.*;
  54.  
  55.  
  56. public interface CellEditor {
  57.  
  58.     /** Returns the value contained in the editor**/
  59.     public Object getCellEditorValue();
  60.  
  61.     /**
  62.      * Ask the editor if it can start editing using <I>anEvent</I>.
  63.      * <I>anEvent</I> is in the invoking component coordinate system.
  64.      * The editor can not assume the Component returned by
  65.      * getCellEditorComponent() is installed.  This method is intended
  66.      * for the use of client to avoid the cost of setting up and installing
  67.      * the editor component if editing is not possible.
  68.      * If editing can be started this method returns true.
  69.      * 
  70.      * @param    anEvent        the event the editor should use to consider
  71.      *                whether to begin editing or not.
  72.      * @return    true if editing can be started.
  73.      * @see #shouldSelectCell()
  74.      */
  75.     public boolean isCellEditable(EventObject anEvent);
  76.  
  77.     /**
  78.      * Tell the editor to start editing using <I>anEvent</I>.  It is
  79.      * up to the editor if it want to start editing in different states
  80.      * depending on the exact type of <I>anEvent</I>.  For example, with
  81.      * a text field editor, if the event is a mouse event the editor
  82.      * might start editing with the cursor at the clicked point.  If
  83.      * the event is a keyboard event, it might want replace the value
  84.      * of the text field with that first key, etc.  <I>anEvent</I>
  85.      * is in the invoking component's coordinate system.  A null value
  86.      * is a valid parameter for <I>anEvent</I>, and it is up to the editor
  87.      * to determine what is the default starting state.  For example,
  88.      * a text field editor might want to select all the text and start
  89.      * editing if <I>anEvent</I> is null.  The editor can assume
  90.      * the Component returned by getCellEditorComponent() is properly
  91.      * installed in the clients Component hierarchy before this method is
  92.      * called. <p>
  93.      *
  94.      * The return value of shouldSelectCell() is a boolean indicating whether
  95.      * the editing cell should be selected or not.  Typically, the return
  96.      * value is true, because is most cases the editing cell should be
  97.      * selected.  However, it is useful to return false to keep the selection
  98.      * from changing for some types of edits.  eg. A table that contains
  99.      * a column of check boxes, the user might want to be able to change
  100.      * those checkboxes without altering the selection.  (See Netscape
  101.      * Communicator for just such an example)  Of course, it is up to
  102.      * the client of the editor to use the return value, but it doesn't
  103.      * need to if it doesn't want to.
  104.      *
  105.      * @param    anEvent        the event the editor should use to start
  106.      *                editing.
  107.      * @return    true if the editor would like the editing cell to be selected
  108.      * @see #isCellEditable()
  109.      */
  110.     public boolean shouldSelectCell(EventObject anEvent);
  111.  
  112.     /**
  113.      * Tell the editor to stop editing and accept any partially edited
  114.      * value as the value of the editor.  The editor returns false if
  115.      * editing was not stopped, useful for editors which validates and
  116.      * can not accept invalid entries.
  117.      *
  118.      * @return    true if editing was stopped
  119.      */
  120.     public boolean stopCellEditing();
  121.  
  122.     /**
  123.      * Tell the editor to cancel editing and not accept any partially
  124.      * edited value.
  125.      */
  126.     public void cancelCellEditing();
  127.  
  128.     /**
  129.      * Add a listener to the list that's notified when the editor starts,
  130.      * stops, or cancels editing.
  131.      *
  132.      * @param    l        the CellEditorListener
  133.      */  
  134.     public void addCellEditorListener(CellEditorListener l);
  135.  
  136.     /**
  137.      * Remove a listener from the list that's notified
  138.      *
  139.      * @param    l        the CellEditorListener
  140.      */  
  141.     public void removeCellEditorListener(CellEditorListener l);
  142. }
  143.